#include "GameOverState.h"
#include "TextureManager.h"
#include "Game.h"
#include "PlayState.h"
#include "MenuState.h"
#include "AnimatedGraphic.h"
#include "MenuButton.h"


const std::string GameOverState::GameOverID = "GAMEOVERSTATE";

void GameOverState::Update()
{
	for(int i = 0; i < mGameObjects.size(); i++)
	{
		mGameObjects[i]->Update();
	}
}

void GameOverState::Draw()
{
	for(int i = 0; i < mGameObjects.size(); i++)
	{
		mGameObjects[i]->Draw();
	}
}

bool GameOverState::OnEnter()
{
	if(!TextureManager::Instance()->Load(".\\assets\\button.png", "playbutton", Game::Instance()->getRenderer()))
		return false;

	if(!TextureManager::Instance()->Load(".\\assets\\exit.png", "exitbutton", Game::Instance()->getRenderer()))
		return false;

	if(!TextureManager::Instance()->Load(".\\assets\\gameover.png", "gameover", Game::Instance()->getRenderer()))
		return false;

	GameObject* button1 = new MenuButton(new LoadedParams(100, 100, 400, 100, "playbutton"), gameoverToPlay);
	GameObject* button2 = new MenuButton(new LoadedParams(100, 300, 400, 100, "exitbutton"), gameoverToMenu);
	GameObject* gameover = new AnimatedGraphic(new LoadedParams(100, 450, 190, 30, "gameover"), 2, 2);

	mGameObjects.push_back(button1);
	mGameObjects.push_back(button2);
	mGameObjects.push_back(gameover);

	printf("Entering GameOver");
	return true;
}

bool GameOverState::OnExit()
{
	for(int i = 0; i < mGameObjects.size(); ++i)
	{
		mGameObjects[i]->Shutdown();
	}

	mGameObjects.clear();
	TextureManager::Instance()->clearFromTextureMap("playbutton");
	TextureManager::Instance()->clearFromTextureMap("exitbutton");
	printf("Exiting MenuState");
	return true;
}

void GameOverState::gameoverToPlay()
{
	Game::Instance()->getGameStateMachine()->changeState(new PlayState());
}

void GameOverState::gameoverToMenu()
{
	Game::Instance()->getGameStateMachine()->changeState(new MenuState());
}
